package com.yxh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yxh.base.BaseServiceClass;
import com.yxh.base.PageEntity;
import com.yxh.common.other.Const;
import com.yxh.dao.CheckQuestionDescribeMapper;
import com.yxh.exception.UnitException;
import com.yxh.exception.UserException;
import com.yxh.pojo.CheckQuestionDescribe;
import com.yxh.pojo.Unit;
import com.yxh.pojo.vo.CheckQuestionDescribeVO;
import com.yxh.service.CheckQuestionDescribeService;
import com.yxh.util.SnowflakeIdWorker;
import com.yxh.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

import static com.yxh.util.APIErrorCode.PARAMS_INVALID;
import static com.yxh.util.APIErrorCode.REGISTER_ERROR;

/**
 * Created by 32988 on 2018/6/5.
 */
@Service
@Transactional
public class CheckQuestionDescribeServiceImpl  implements  CheckQuestionDescribeService{

    @Autowired
    CheckQuestionDescribeMapper checkQuestionDescribeMapper;

    @Override
    public PageInfo getInformation(CheckQuestionDescribe checkQuestionDescribe, Integer limit, Integer offset) {
        PageHelper.startPage(limit, offset);
        List<Map<String,Object>> checkQuestionDescribeVOListList = checkQuestionDescribeMapper.selectByCheckQuestionDescribe(checkQuestionDescribe);
        PageInfo pageInfo = new PageInfo(checkQuestionDescribeVOListList);
        pageInfo.setList(checkQuestionDescribeVOListList);
        return pageInfo;
    }

    @Override
    public int save(CheckQuestionDescribe record) {
        int count = checkQuestionDescribeMapper.insertSelective(record);
        if (count == 0) {
            throw new UserException(REGISTER_ERROR);
        }
        return count;
    }

    @Override
    public int update(CheckQuestionDescribe record) {

        return checkQuestionDescribeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int delete(String id) {
        if (!StringUtil.isEmpty(id)) {
            String[] arr = id.split(",");
            checkQuestionDescribeMapper.deleteByIds(arr);
        }
        return 0;
    }

    @Override
    public void batchDelete(List<CheckQuestionDescribe> records) {

    }

    @Override
    public CheckQuestionDescribe get(String id) {
        return null;
    }

    @Override
    public CheckQuestionDescribe get(CheckQuestionDescribe record) {
        return null;
    }

    @Override
    public List<CheckQuestionDescribe> getList(CheckQuestionDescribe record) {
        return null;
    }

    @Override
    public List<CheckQuestionDescribe> getAllList(CheckQuestionDescribe record) {
        return null;
    }

    @Override
    public List<CheckQuestionDescribe> getListPage(PageEntity<CheckQuestionDescribe> record) {
        return null;
    }
}
